﻿@using PagedList;
@using PagedList.Mvc;
@model PagedList.IPagedList<YuFeng.Models.Product.ProductCategory>
@{
    ViewBag.Title = "产品分类管理";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}

<style type="text/css">
    .form-group .form-control {
        width: auto;
    }
</style>
<div class="pageheader">
    <h2><i class="fa fa-book"></i> 产品分类管理 <span>产品分类列表</span></h2>
    <div class="breadcrumb-wrapper">
        <span class="label">当前位置：</span>
        <ol class="breadcrumb">
            <li><a href="/Admin/Production/ProductionCenter">产品分类管理</a></li>
            <li class="active">产品分类列表</li>
        </ol>
    </div>
</div>
<div class="contentpanel">
    <div class="row">
        <div class="panel panel-default">
            <div class="panel-body">
                <form class="form-inline pull-right">
                    <div class="form-group">
                        <label class="">分类名称：</label>
                        <input type="text" class="form-control" name="Name" value="@ViewBag.Name" placeholder="分类名称">
                    </div>
                    <button type="submit" class="btn btn-success">查找</button>
                </form>
            </div>
        </div>
    </div>
    <div class="mb20"></div>
    <div class="row">
        <div class="table-responsive">
            <table class="table table-hidaction table-hover">
                <thead>
                    <tr>
                        <th class="col-lg-2">分类名称</th>
                        <th class="col-lg-2">排序</th>
                        <th class="col-lg-2">创建时间</th>
                        <th class="col-lg-1 text-center">
                            <a class="btn btn-success" href="@Url.Action("CreateCategory", "Production", new { Areas = "Admin" })" title="添加产品分类">
                                <span class="glyphicon glyphicon-plus-sign"></span>
                                添加产品分类
                            </a>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model)
                    {
                        <tr>
                            <td>@item.Name</td>
                            <td>@item.Sort</td>
                            <td>@item.CreatedTime.ToString("yyyy/MM/dd")</td>
                            <td class="text-center">
                                <a href="/Admin/Production/EditCategory?id=@item.Id" title="修改"><i class="fa fa-pencil"></i></a>
                                &nbsp;&nbsp;
                                <a href="javascript:void(0);" class="delete-row" title="删除" onclick="DeleteCategory(this)" data-id="@item.Id"><i class="fa fa-trash-o"></i></a>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>

        </div><!-- table-responsive -->
        <div class="text-right">
            @Html.PagedListPager((PagedList.IPagedList)Model, page => Url.Action("ProductCategory", new
       {
           page,
           name = ViewBag.Name,
       })
                            , PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(
                            new PagedListRenderOptions()
                            {
                                LinkToPreviousPageFormat = "上一页",
                                LinkToNextPageFormat = "下一页",
                                MaximumPageNumbersToDisplay = 5
                            }, new AjaxOptions()
                            {
                                HttpMethod = "GET",
                                UpdateTargetId = "course-list"
                            }))
        </div>
    </div><!-- row -->
</div>

@section scripts
{
    <script type="text/javascript">
        $(function () {
            $("#main_nav-profiles li").each(function (data) {
                if ($(this).find("a").attr("href").indexOf("ProductCategory") > 0) {
                    $(this).addClass("active");
                }
            });
        });
        var _categoryId;
        var DeleteCategory = function (target) {
            event.preventDefault();
            _categoryId = $(target).data("id");
            title = "确认信息";
            body = "确定要删除该产品分类吗？";
            footer = "<button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">取消</button><button type=\"button\" class=\"btn btn-primary\" onclick=\"DeleteCategoryDone();\">确定</button>";
            modal = Tips(body, title, null, null, footer);
        }
        var DeleteCategoryDone = function () {
            $.ajax({
                type: "POST",
                url: "/Admin/Production/DeleteCategory",
                data: { id: _categoryId },
                datatype: "json",
                success: function (data) {
                    if (data.status) {
                        modal = Tips(data.data, "提示");
                        setTimeout(function () { location.reload(); }, 1000);
                    }
                    else {
                        modal = Tips(data.errmsg, "提示");
                        setTimeout(function () { modal.modal('hide'); }, 1000);

                    }
                }
            })
        };
    </script>
}


